package controllerLayer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.common.ByteMatrix;


public class BarCodeWriter {
	public static void main(String args[]){
		write();
	}
	public static void write()
	{
		String text = "98376373783"; // this is the text that we want to encode

		int width = 400;
		int height = 300; // change the height and width as per your requirement

		// (ImageIO.getWriterFormatNames() returns a list of supported formats)
		String imageFormat = "png"; // could be "gif", "tiff", "jpeg" 
		

		ByteMatrix bitMatrix;

		try {
			bitMatrix = new Code128Writer().encode(text, BarcodeFormat.CODE_128, width, height);
			MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, new FileOutputStream(new File("barcode.png")));

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (WriterException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
